package com.ruoyi.web.controller.user;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.user.domain.UserSignRecord;
import com.ruoyi.user.service.UserSignRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户签到Controller
 *
 * @author ruoyi
 * @date 2024-01-10
 */
@Api(tags = "用户签到")
@RestController
@RequestMapping("/user/sign/record")
public class UserSignRecordController extends BaseController {
    @Autowired
    private UserSignRecordService userSignRecordService;

    /**
     * 查询用户签到列表
     */
    @ApiOperation("查询用户签到列表")
    @PreAuthorize("@ss.hasPermi('user:sign:record:list')")
    @PostMapping("/list")
    public TableDataInfo list(UserSignRecord userSignRecord) {
        startPage();
        List<UserSignRecord> list = userSignRecordService.selectUserSignRecordList(userSignRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户签到列表
     */
    @ApiOperation("导出用户签到列表")
    @PreAuthorize("@ss.hasPermi('user:sign:record:export')")
    @Log(title = "用户签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserSignRecord userSignRecord) {
        List<UserSignRecord> list = userSignRecordService.selectUserSignRecordList(userSignRecord);
        ExcelUtil<UserSignRecord> util = new ExcelUtil<>(UserSignRecord.class);
        util.exportExcel(response, list, "用户签到数据");
    }
}
